| Conditions | 5 |
| Paths | 18 |
| Total Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 32 | function httpRequest(file, data, type) { |
||
| 33 | var xhrObject = null; |
||
| 34 | var isChrome = navigator.userAgent.toLowerCase().indexOf("chrome") > -1; |
||
| 35 | |||
| 36 | if (document.getElementById("menu_action") !== null) { |
||
| 37 | document.getElementById("menu_action").value = "action"; |
||
| 38 | } |
||
| 39 | |||
| 40 | if(window.XMLHttpRequest) { |
||
| 41 | // Firefox |
||
| 42 | xhrObject = new XMLHttpRequest(); |
||
| 43 | } else if(window.ActiveXObject) { |
||
| 44 | // Internet Explorer |
||
| 45 | xhrObject = new ActiveXObject("Microsoft.XMLHTTP"); |
||
| 46 | } else { |
||
| 47 | // XMLHttpRequest not supported by browser |
||
| 48 | alert("Your browser does not support XMLHTTPRequest objects ..."); |
||
| 49 | return; |
||
| 50 | } |
||
| 51 | |||
| 52 | if (type === "GET") { |
||
| 53 | xhrObject.open("GET", file + "?" + data, true); |
||
| 54 | xhrObject.send(null); |
||
| 55 | } else { |
||
| 56 | xhrObject.open("POST", file, true); |
||
| 57 | xhrObject.onreadystatechange = function() { |
||
| 58 | if(xhrObject.readyState === 4) { |
||
| 59 | eval(xhrObject.responseText); |
||
| 60 | //Check if query is for user identification. If yes, then reload page. |
||
| 61 | if (data !== "" && data !== undefined && data.indexOf("ype=identify_user") > 0 ) { |
||
| 62 | if (isChrome === true ) { |
||
| 63 | // Needed pause for Chrome |
||
| 64 | pauseInExecution(100); |
||
| 65 | } |
||
| 66 | if (type === "") { |
||
| 67 | if (document.getElementById("erreur_connexion").style.display === "") { |
||
| 68 | //rise an error in url. This in order to display the eror after refreshing |
||
| 69 | window.location.href = encodeURI("index.php?error=rised"); |
||
| 70 | } else { |
||
| 71 | window.location.href = encodeURI("index.php"); |
||
| 72 | } |
||
| 73 | } else { |
||
| 74 | if (type === "?error=rised") { |
||
| 75 | if (document.getElementById("erreur_connexion").style.display === "none") { |
||
| 76 | // Clean error in url |
||
| 77 | type = ""; |
||
| 78 | } else { |
||
| 79 | // Maintain the ERROR |
||
| 80 | type = "?error=rised"; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | // Redirection |
||
| 84 | window.location.href = encodeURI("index.php" + type); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | xhrObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8"); |
||
| 90 | xhrObject.send(data); |
||
| 91 | } |
||
| 92 | } |